#include "general.h" 
#include "globals.h"
#include "header.h"

DEFINE_EVENT_TYPE(EVENT_NAME_CATEGORY_CHANGED)
BEGIN_EVENT_TABLE(CHeader, wxPanel)
END_EVENT_TABLE()

CHeader::CHeader( 
	wxWindow *parent, wxWindowID id, 
	const wxPoint &position, const wxSize& size, long style 
	)
    : wxPanel( parent, id, position, size, style)
{
	CreateButtons();
}

void CHeader::CreateButtons()
{
	wxBoxSizer* pSizer = new wxBoxSizer(wxHORIZONTAL);
	wxButton* pButton;
	int id = 100;
	wxString name;
	std::list<OperationCategory::Base*>::iterator iter;
	for (iter=g_operation_categories.begin(); iter!=g_operation_categories.end(); ++iter)
	{
		OperationCategory::Base* pBase = *iter;
		
		id ++;
		pBase->GetName(name);
		pButton = new wxButton(this, id, name);
		Connect(id, wxEVT_COMMAND_BUTTON_CLICKED, 
			wxCommandEventHandler(CHeader::OnButtonClicked)
			);
		
		pSizer->Add(pButton, 0, wxALIGN_CENTER|wxALIGN_CENTER_VERTICAL);

		m_map1[id] = pBase;
	}
	pSizer->SetMinSize(0, 50);

	SetSizer(pSizer);

}

CHeader::~CHeader(void)
{
}

void CHeader::OnCreate(wxWindowCreateEvent& event)
{
	if (event.GetId() != GetId())
		return;

}

void CHeader::OnButtonClicked(wxCommandEvent& event)
{
	std::list<OperationCategory::Base*>::iterator iter;
	for (iter=g_operation_categories.begin(); iter!=g_operation_categories.end(); ++iter)
	{
		OperationCategory::Base* pBase = *iter;
		pBase->Activate(false);
	}

	OperationCategory::Base* pBase = m_map1[event.GetId()];
	pBase->Activate();
}